import java.util.*;

public class Main {
    public static void main(String[] args) {
        System.out.println("----------创建空的线性表---------");
        LinkList<String> L = new LinkList<String>();
        System.out.println("线性表长度="+L.getSize());

        System.out.println("----------用指定数组创建线性表---------");
        String a[]= {"x","c","u","f","d","u","c"};
        L.createList(a);	//注意头插法和尾插法的区别
        System.out.println(L.toString());
        System.out.println("线性表长度="+L.getSize());

        System.out.println("----------求指定序号元素---------");
        try {
            System.out.println("序号3的元素是："+L.getElem(3));
            System.out.println("序号8的元素是："+L.getElem(8));
        }
        catch(Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        System.out.println("----------设置指定序号元素---------");
        try {
            L.setElem(3, "e");
            System.out.println("序号3的元素设置为："+L.getElem(3));
            L.setElem(8, "x");
            System.out.println("序号8的元素设置为："+L.getElem(8));
        }
        catch(Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        System.out.println("----------求元素的序号---------");
        System.out.println("字符c的位置："+ L.getNo("c"));
        System.out.println("字符n的位置："+ L.getNo("n"));
        L.add("n");
        System.out.println(L.toString());
        System.out.println("线性表长度="+L.getSize());

        System.out.println("----------插入元素---------");
        try {
            L.insert(3,".");
            L.insert(6,".");
            System.out.println(L.toString());
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        System.out.println("----------删除元素---------");
        try {
            L.delete(6);
            L.insert(7,".");
            System.out.println(L.toString());
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        System.out.println("----------插入元素 异常---------");
        try {
            L.insert(L.getSize()+1,"\\");
            System.out.println(L.toString());
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        try {
            L.insert(-1,"www.");
            System.out.println(L.toString());
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        L.insert(0,"www.");
        System.out.println(L.toString());

        System.out.println("----------删除元素 异常---------");
        try {
            L.delete(-1);
            System.out.println(L.toString());
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        try {
            L.delete(L.getSize());
            System.out.println(L.toString());
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        L.delete(0);
        System.out.println(L.toString());

        System.out.println("----------设置长度---------");
        try {
            L.setSize(L.getSize()+1);
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        L.setSize(8);
        System.out.println("长度为8的线性表："+ L.toString());

        System.out.println("----------交换---------");
        try {
            System.out.println("开头与最后交换");
            L.swap(0, L.getSize()-1);
            System.out.println(L.toString());

            L.swap(0, L.getSize()-1);
            System.out.println(L.toString());
        }
        catch (Exception e) {
            System.out.println("! ! ! " + e.getMessage());
        }

        System.out.println("Test end. ");

    }
}
